# -*- coding: utf-8 -*-
import md5
import datetime

from models.account import Account
from models.product import (Milk, MilkBrand)
from models.menu import MenuType, MenuItem

def get_now__year_month_day():
    now = datetime.datetime.now()
    return unicode(now.strftime('%Y%-%m-%d'))

def add_users():
    '''用于增加用户'''
    #增加用户admin
    name = 'admin'
    m1 = md5.new()
    m1.update('admin')
    password = m1.hexdigest()
    group = 'administrator'
    Account(name=name, password=password, group=group).put()
    
def add_menus():
    '''用于增加菜单和菜单项'''
    #增加菜单类型
    mt1 = MenuType(name=u'商品销售', description=u'商品销售类型菜单', slug=u'sale_mange')
    mt2 = MenuType(name=u'库存管理', description=u'库存管理类型菜单', slug=u'product_mange')
    mt1 = mt1.put().id()
    mt2 = mt2.put().id()
    
    #增加菜单项
    root1 = MenuItem(name=u'销售操作', leaf=False, menu_type=mt1, parent_menuitem=9999)
    root1 = root1.put().id()
    root2 = MenuItem(name=u'入库记录', leaf=False, menu_type=mt2, parent_menuitem=9999)
    root2 = root2.put().id()
    root3 = MenuItem(name=u'库存数量', leaf=False, menu_type=mt2, parent_menuitem=9999)
    root3 = root3.put().id()    
    
    MenuItem(name=u'日常销售', leaf=True, menu_type=mt1, parent_menuitem=root1).put()
    MenuItem(name=u'奶粉', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'辅食', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'保健品', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'喂养用品', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'尿裤/湿巾/护脐带', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'洗护用品', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'童车', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'床/椅', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'玩具', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'寝具', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'图书音像', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'妈妈用品', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'生活电器', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'服装', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'礼盒套装', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'财务', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'赠品', leaf=True, menu_type=mt2, parent_menuitem=root2).put()
    MenuItem(name=u'其他', leaf=True, menu_type=mt2, parent_menuitem=root2).put()

    MenuItem(name=u'奶粉', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'辅食', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'保健品', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'喂养用品', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'尿裤/湿巾/护脐带', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'洗护用品', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'童车', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'床/椅', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'玩具', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'寝具', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'图书音像', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'妈妈用品', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'生活电器', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'服装', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'礼盒套装', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'财务', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'赠品', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    MenuItem(name=u'其他', leaf=True, menu_type=mt2, parent_menuitem=root3).put()
    
def add_milks():
    '''增加奶粉'''
    
    # 增加品牌
    MilkBrand(name=u'多美滋').put()
    MilkBrand(name=u'惠氏').put()
    MilkBrand(name=u'美赞臣').put()
    MilkBrand(name=u'施恩').put()
    MilkBrand(name=u'南山').put()
    MilkBrand(name=u'圣元').put()
    MilkBrand(name=u'亨氏').put()

    Milk(brand=u'多美滋',
         breed=u'牛奶',
         stage=u'0--6个月',
         wrap=u'盒装',
         price=134.0,
         num=56).put()
         
    Milk(brand=u'多美滋',
         breed=u'牛奶',
         stage=u'0--6个月',
         wrap=u'厅装',
         price=134.0,
         num=56).put()         

    Milk(breed=u'牛奶',
         brand=u'惠氏',
         stage=u'0--6个月',
         wrap=u'盒装',
         price=125.0,
         num=100).put()
         
    Milk(breed=u'牛奶',
         brand=u'美赞臣',
         stage=u'0--6个月',
         wrap=u'盒装',
         price=126.5,
         num=88).put()

    Milk(breed=u'牛奶',
         brand=u'施恩',
         stage=u'12--18个月',
         wrap=u'盒装',
         price=125.0,
         num=95).put()  
         
    Milk(breed=u'牛奶',
         brand=u'南山',
         stage=u'6--12个月',
         wrap=u'盒装',
         price=116.5,
         num=70).put()

    Milk(breed=u'牛奶',
         brand=u'圣元',
         stage=u'0--6个月',
         wrap=u'盒装',
         discount=0.58,
         price=105.0,
         num=38).put()                         
         
    Milk(breed=u'牛奶',
         brand=u'亨氏',
         stage=u'0--6个月',
         wrap=u'厅装',
         price=135.0,
         num=43).put()             